package com.bah.tract.client.ui;

import javax.swing.DefaultComboBoxModel;

import com.bah.tract.service.Project;
import com.bah.tract.service.ProjectList;

public class ProjectComboModel extends DefaultComboBoxModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ProjectComboModel(final ProjectList projects) {
		for (final Project project : projects.getProject()) {
			addElement(new ProjectLabel(project));
		}
	}

	public class ProjectLabel {

		@Override
		public final int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime
					* result
					+ ((project == null) ? 0 : Long.valueOf(project.getId())
							.hashCode());
			return result;
		}

		@Override
		public final boolean equals(final Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final ProjectLabel other = (ProjectLabel) obj;
			if (!getOuterType().equals(other.getOuterType())) {
				return false;
			}
			if (project == null) {
				if (other.project != null) {
					return false;
				}
			} else if (project.getId() != other.project.getId()) {
				return false;
			}
			return true;
		}

		private final Project project;

		public final Project getProject() {
			return project;
		}

		public ProjectLabel(final Project project) {
			this.project = project;
		}

		@Override
		public final String toString() {
			return project.getLabel();
		}

		private ProjectComboModel getOuterType() {
			return ProjectComboModel.this;
		}

	}
}
